<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<base target="_self" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<title>添加供货商信息</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/json2.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>


<script type="text/javascript">
	//添加信息按钮响应函数
	function deal() {
		$('#AddFoodForm').form('submit', {
			url : '<c:url value='/supplier/saveSupplier.do'/>', //查询提交路径
			onSubmit : function()//提交按钮相应函数
			{
				var password = $('#password').val();
                var password2 = $('#password2').val();
                if (password == null) {
                    $.messager.alert("错误", "密码不能为空!", 'error');
                    return false;
                } else if (password != password2) {
                    $.messager.alert("错误", "密码两次输入不同!", 'error');
                    return false;
                }
				return $('#AddFoodForm').form('validate');
			},
			success : function(data) {
				data = eval('(' + data + ')');
				if (data.success) {
					$.messager.alert('系统提示', '添加成功', 'info', function() {
						window.close();
					});
				} else {
					var message = "";
					if (data.msg == "msg0004") {
						message = "系统已存在该供货商公司名！";
					}
					$.messager.alert("提示", message, 'warning');
				}
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});

	}

	$(function() {
		//
		document.getElementById('zzy').style.display = 'none';
        document.getElementById('zzy1').style.display = 'none';
        document.getElementById('zzy1menu').style.display = 'none';


		// 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		$('#SupType').combobox({
			url : '<c:url value='/mater/pulldownMaterType.do'/>',
			editable : false, //不可编辑状态  
			cache : false,
			panelHeight : '150',
			valueField : 'materType',
			textField : 'materTypename',
			required : true

		});
		// 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		$('#supId').combobox({
			url : "<c:url value='/store/pulldownSupId.do?space=0'/>",
			editable : false, //不可编辑状态  
			cache : false,
			panelHeight : '150',
			valueField : 'supId',
			textField : 'supName',
			required : true
		});
		// 下拉框选择控件，下拉框的内容是动态查询数据库信息  
		$('#isActive').combobox({
			data : [ {
				"isActive" : "0",
				"isActiveName" : "有效"
			}, {
				"isActive" : "1",
				"isActiveName" : "失效"
			} ],
			editable : false, //不可编辑状态  
			cache : false,
			panelHeight : '50',
			valueField : 'isActive',
			textField : 'isActiveName',
			required : true
		});
		$('#province').combobox({
            url : '<c:url value='/user/pullDownProvince.do'/>',
            editable : true, //不可编辑状态  
            cache : false,
            panelHeight : '150',
            valueField : 'areaid',
            textField : 'name',
            required : true,
            onChange : function(newValue, oldValue) {
                $.post('<c:url value='/user/pullDownCity.do'/>', {
                    parentId : newValue
                }, function(data) {
                    $('#city').combobox("clear").combobox('loadData', data);
                }, 'json');
            }
        });
        $('#city').combobox({
            valueField : 'areaid',
            textField : 'name',
            editable : false,
            url : '<c:url value='/user/pullDownCity.do'/>',
            onChange : function(newValue, oldValue) {
                $.post('<c:url value='/user/pullDownCountry.do'/>', {
                    parentId : newValue
                }, function(data) {
                    $('#country').combobox("clear").combobox('loadData', data);
                }, 'json');
            }
        });
        $('#country').combobox({
            url : '<c:url value='/user/pullDownCountry.do'/>',
            valueField : 'areaid',
            textField : 'name',
            editable : false
        });
        $('#userFlag').combobox({
            data : [ {
                "userFlag" : "1",
                "userFlagName" : "不建立员工"
            }, {
                "userFlag" : "2",
                "userFlagName" : "从公司员工列表中选取"
            }, {
                "userFlag" : "3",
                "userFlagName" : "新建员工"
            } ],
            editable : false, //不可编辑状态  
            cache : false,
            valueField : 'userFlag',
            textField : 'userFlagName',
            value:1,
            onSelect : function(rec){    
            	if(rec.userFlag==3){
            		document.getElementById('zzy').style.display = '';
            	}else if(rec.userFlag==1){
            		document.getElementById('zzy').style.display = 'none';
                    document.getElementById('zzy1').style.display = 'none';
                    document.getElementById('zzy1menu').style.display = 'none';
            	}else if(rec.userFlag==2){
                    document.getElementById('zzy').style.display = 'none';
                    document.getElementById('zzy1').style.display = '';

                }
            }
        });
        
        $("#userNameForSup").textbox({
            buttonText:'查询',    
            iconCls:'icon-man', 
            iconAlign:'left',
            editable:false,
            value: "无",
            onClickButton:function(){
                ////校验
                initDateLeft();
                showMsgLeft();
                ShowDiv();
                //
                var left = $('#left').listbox();
                var items = left.getSelected();
                left.removeRange(items);

                var right = $('#right').listbox();
                var itemsr = right.getSelected();
                right.removeRange(itemsr);

                $('#left').listbox().reload({
                    data : dataLeft,
                    ajaxsettings : {
                        data : {
                            id : 'a'
                        }
                    }
                });
            }
        });
	});
	//初始化showMsg
    function initDateLeft(){
        $.ajax({
            async : false,
            url : "<c:url value='/supplier/getUserForSupplierCompany.do'/>" +"?levelIdcopy="+levelId+"&companyUser=${companyUser }",
            type : "post",
            success : function(data) {
                dataLeft = data;
                if (typeof (dataLeft) == 'string' && dataLeft!='') {
                        dataLeft = JSON.parse(dataLeft);
                }
            }
        });
    }
    function showMsgLeft() {
        $('#left').listbox({
            data : dataLeft,
            height : 300,
            width : 200,
            dndscope : 'demo',
            dnd : false,
            multiselect : true,
            selectchange : function(data) {
                if (data && data.length > 0) {
                    $('#btnRight').attr('disabled', false);
                } else {
                    $('#btnRight').attr('disabled', true);
                }
            }
        });
        $('#right').listbox({
            //data: data,
            height : 300,
            width : 200,
            dndscope : 'demo',
            dnd : true,
            multiselect : true
        });
        $('#btnRightAll').click(function() {
            var left = $('#left').listbox();
            var items = left.getDatas();
            left.clear();
            $('#right').listbox().addRange(items);
        });
        $('#btnLeftAll').click(function() {
            var right = $('#right').listbox();
            var items = right.getDatas();
            right.clear();
            $('#left').listbox().addRange(items);
        });
        $('#btnRight').click(function() {
            var left = $('#left').listbox();
            var items = left.getSelected();
            left.removeRange(items);
            $('#right').listbox().addRange(items);
        });
        $('#btnLeft').click(function() {
            var right = $('#right').listbox();
            var items = right.getSelected();
            right.removeRange(items);
            $('#left').listbox().addRange(items);
        });
        $('#btnRemove').click(function() {
            $('#right').listbox().removeRange([ {
                value : 2
            }, {
                value : 26
            } ]);
        });
        $('#btnSelect').click(function() {
            var selected = $('#right').listbox().getSelected();
            var msg = 'Selected count is: ' + selected.length;
            if (selected.length > 0) {
                msg += ', The first item text is: ' + selected[0].text;
            }
            msg += '.';
            alert(msg);
        });
        $('#btnGetItems').click(function() {
            var selected = $('#right').listbox('getDatas');
            alert('Items count is: ' + selected.length);
        });
        $('#btnSetSelection').click(function() {
            $('#left').listbox('setSelection', 1);
        });
        $('#btnReload').click(function() {
            var left = $('#left').listbox();
            var items = left.getSelected();
            left.removeRange(items);

            var right = $('#right').listbox();
            var itemsr = right.getSelected();
            right.removeRange(itemsr);

            $('#left').listbox().reload({
                data : datal,
                ajaxsettings : {
                    data : {
                        id : 'a'
                    }
                }
            });
        });
        $('#select').click(function() {
            Loading.Hide();
            document.getElementById('zzy1menu').style.display = 'none';

            var right = $('#right').listbox();
            var items = right.getDatas();
            
            var  userNameForSup="";
            var userIdForSup = "";
            if (items.length > 0) {
                for ( var e in items) {
                	userNameForSup = userNameForSup + items[e].text + ',';
                	userIdForSup = userIdForSup + items[e].value + ',';
                }
                userNameForSup = userNameForSup.substring(0, userNameForSup.length - 1);
                userIdForSup = userIdForSup.substring(0, userIdForSup.length - 1);
            }
            if (userNameForSup != '' && userIdForSup != '') {
                document.getElementById('userNameForSup').value = userNameForSup;
                document.getElementById('userIdForSup').value = userIdForSup;
            } else {
            	document.getElementById('userNameForSup').value = "";
                document.getElementById('userIdForSup').value = "";
            }
        });
        $('#noselect').click(function() {
            Loading.Hide();
            document.getElementById('zzy').style.display = 'none';
        });
    }
    
    function searchInfo(){
        $('#searchForm').form('submit',
            {
                url:'<c:url value='/user/userlevelChina.do'/>', //查询提交路径
                onSubmit:function()//提交按钮相应函数
                    {
                        return $('#searchForm').form('validate');
                    },
                success:function(data){
                    data = eval( "("+data+")" );
                    var left = $('#left').listbox();
                    var items = left.getSelected();
                    left.removeRange(items);

                    var right = $('#right').listbox();
                    var itemsr = right.getSelected();
                    right.removeRange(itemsr);

                    $('#left').listbox().reload({
                        data : data,
                        ajaxsettings : {
                            data : {
                                id : 'a'
                            }
                        }
                    });
                },
                error:function(){
                    $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                    return;
                }
            }
        );
    }
</script>
</head>

<body>
	<table width="90%" align="center">
		<tr>
			<td>
				<div style="height: auto; background: #fafafa; padding: 5px;"
					class="easyui-panel" title="添加供货商信息" iconCls="icon-save"
					collapsible="true" minimizable="false" maximizable="false"
					closable="false">

					<form id="AddFoodForm" name="AddFoodForm" method="post">
						<table cellpadding="5">
							<tr>
								<td>配送中心名称:</td>
								<td><input class="easyui-textbox" type="text" name="realName" required="true" validType="length[1,100]" /></td>
							</tr>
							<tr>
								<td>机构编码:</td>
								<td><input class="easyui-textbox" type="text" name="organId" /></td>
								<td>邮箱:</td>
								<td><input class="easyui-textbox" type="email" name="email" validType="email" validType="length[1,100]"  required="true" /></td>
							</tr>
							<tr>
								<td>电话:</td>
								<td><input class="easyui-numberbox" type="userPhone" name="userPhone" required="true" /></td>
							</tr>
							<tr>
                                <td>手机:</td>
                                <td><input class="easyui-numberbox"   name="mobile" id="mobile"  required="true"></td>
                            </tr>
							<tr>
								<td>是否有效:</td>
								<td><select class="easyui-combobox" name="isActive">
										<option value="0">有效</option>
										<option value="1">失效</option>
								</select></td>
							</tr>

							<tr>
								<td>省:</td>
								<td><input class="easyui-combobox" name="province" id="province" required="true" /></td>
							</tr>

							<tr>
								<td>市:</td>
								<td><input class="easyui-combobox" name="city" id="city" required="true" /></td>
							</tr>

							<tr>
								<td>区:</td>
								<td><input class="easyui-combobox" name="country" id="country" required="true" /></td>
							</tr>
							
							<tr>
                                <td>街:</td>
                                <td><input class="easyui-textbox" type="street" name="street" validType="length[1,50]"  required="true" /></td>
                            </tr>
                            <tr>
                                <td>管理员工：</td>
                                <td><input class="easyui-combobox" id="userFlag" editable="false" name="userFlag"></input></td>
                            </tr>
						</table>
						<br> <br>
                        
                      <br>
                        -----------------------供货类别选择----------------------------<br><br>
                      <c:forEach var="code" items="${typeList}" varStatus="status">
                           <input class="menuIds" type="checkbox" name="suptypes" value="${code.codeOder }">${code.describ }</input>
                            <c:if test="${status.count % 5 == 0}">
                      <br><br>
                      </c:if>
                            
                      </c:forEach>
                      <br><br>
                      
                      -----------------------页面角色选择----------------------------<br>
                      <div id="zzy">
                      <table cellpadding="5">
                      <tr>
                          <td>登录用户名:</td>
                          <td><input class="easyui-textbox" type="text" name="userName" required="true" validType="length[1,30]" /></td>
                      </tr>
                      <tr>
                          <td>密码:</td>
                          <td><input class="easyui-textbox" type="password" id="password" required="true" validType="length[1,100]" name="password" /></td>
                          <td>确认密码:</td>
                          <td><input class="easyui-textbox" type="password" id="password2" required="true" validType="length[1,100]" name="password2" /></td>
                      </tr>
                      </table>
                      
                      <div>
                        <c:forEach var="role" items="${rolelist}" varStatus="st">
                            <input class="easyui-validatebox" type="checkBox" name="roles"
                                value="${role.roleId }">${role.roleName }</input>
                            <c:if test="${st.count % 5 == 0}">
                                <br>
                                <br>
                            </c:if>

                        </c:forEach>
                        <br/>
                        <br/>
                      </div>
                      </div>
                      <div id="zzy1">
                          <table cellpadding="5">
                            <tr>
                              <td>员工</td>
                              <td colspan="3"><input style="width:360px" id="userNameForSup" name="userNameForSup" ></input></td>
                              <td><input type="hidden" id="userIdForSup" name="userIdForSup" ></input></td>
                            </tr>
                          </table>
                      </div>
						<a class="easyui-linkbutton" onclick="deal()">添加</a>
						
						<input type="hidden" name="companyId" id="companyId" value="${companyId }" required="true" />
					</form>

				</div>
			</td>
		</tr>
	</table>
	
    <div  style='position: absolute; left: 40px; top: 40px; z-index: 101; display: none; background-color: #FFFFFF; border-radius: 10px; width: 550px;'
        id="zzy1menu">
        <table align="center">
            <tr>
                <td colspan="3">
                    <form id="searchForm" name="searchForm" method="post" accept-charset="UTF-8">
                    <div
                        style="height: auto; width: 470px; background: #fafafa; padding: 5px;"
                        class="easyui-panel" title="查询" iconCls="icon-search"
                        collapsible="true" minimizable="false" maximizable="false"
                        closable="false">
                        <table>
                            <tr>
                                <td>省:</td>
                                <td><input class="easyui-combobox" name="provinceShow"
                                    id="provinceShow" required="true" /></td>
                                <td>市:</td>
                                <td><input class="easyui-combobox" name="cityShow"
                                    id="cityShow" required="true" /></td>
                            </tr>
                            <tr>
                                <td>区:</td>
                                <td><input class="easyui-combobox" name="countryShow"
                                    id="countryShow" required="true" /></td>
                            </tr>
                            <tr>
                                <td>职位:</td>
                                <td><input class="easyui-combobox" name="userlevel"
                                    id="userlevel" required="true" /></td>
                                <td colspan="2"><a href="#" class="easyui-linkbutton"
                                    data-options="iconCls:'icon-search'" style="width: 60px"
                                    onclick="searchInfo()">查询</a></td>
                            </tr>
                            <input class="easyui-validatebox" type="hidden" name="levelIdcopy" id="levelIdcopy"  />
                            
                        </table>
                    </div>
                    </form>
                </td>
            </tr>
            <tr>
                <td>
                    <ul id="left">
                    </ul>
                </td>
                <td><input type="button" value="&gt;&gt;" id="btnRightAll"
                    style="width: 50px;" /><br /> <input type="button" value="&gt;"
                    id="btnRight" style="width: 50px;" /><br /> <input type="button"
                    value="&lt;" id="btnLeft" style="width: 50px;" /><br /> <input
                    type="button" value="&lt;&lt;" id="btnLeftAll" style="width: 50px;" />
                </td>
                <td>
                    <ul id="right">
                    </ul>
                </td>
            </tr>
        </table>
        <table align="center">
            <tr>
                <!--  
                <td><input type="button" value="Add Item" id="btnAdd" /></td>
                <td><input type="button" value="Remove Item" id="btnRemove" /></td>
                <td><input type="button" value="Get Select" id="btnSelect" /></td>
                <td><input type="button" value="Get Items" id="btnGetItems" /></td>
                <td><input type="button" value="SetSelection (value equal to '1')" id="btnSetSelection" /></td>
                <td><input type="button" value="Reload" id="btnReload" /></td>
                -->
                <td><input type="button" value="取消" id="noselect" /></td>
                <td width="200px"></td>
                <td><input type="button" value="选择" id="select" /></td>

            </tr>
        </table>
    </div>
</body>
</html>